import type { BasePageList } from '@/types/base'
import { request } from '@/utils/request'
import {
  SourcemapListParams,
  Sourcemap,
  SourcemapErrorParams,
  SourcemapErrorResult,
} from '@/types/sourcemap'

export function getSourcemapListApi(
  params: SourcemapListParams = { page: 1, pageSize: 10 }
): Promise<BasePageList<Sourcemap>> {
  return request.get('/sourcemap/list', { params })
}

export function createSourcemapApi(data: Sourcemap): Promise<Sourcemap> {
  return request.post('/sourcemap/create', data)
}

export function updateSourcemapApi(id: number, data: Partial<Sourcemap>): Promise<Sourcemap> {
  return request.put(`/sourcemap/${id}`, data)
}

export function downloadSourcemapApi(id: number): Promise<void> {
  return request.get(`/sourcemap/download/${id}`, {
    responseType: 'blob',
  })
}

export function findBugApi(params: SourcemapErrorParams): Promise<SourcemapErrorResult> {
  return request.get(`/sourcemap/error`, { params })
}

export function deleteSourcemapApi(id: number): Promise<void> {
  return request.delete(`/sourcemap/${id}`)
}
